package cn.z2huo.leetcode.problem.NO_0001;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.List;

/**
 * @author z2huo
 */
@Slf4j
class SolutionTest2 {

    @Data
    @Accessors(chain = true)
    @NoArgsConstructor
    @AllArgsConstructor
    static class InputOutput {

        private int[] source;

        private int target;

        private int[] result;
    }

    private final List<InputOutput> inputOutputList = List.of(
            new InputOutput(new int[]{3, 2, 4}, 6, new int[]{1, 2}),
            new InputOutput(new int[]{1, 3, 7, 5, 11, 4, 8}, 7, new int[]{1, 5}),
            new InputOutput(new int[]{1, 3, 2, 11, 8, 4, 6}, 8, new int[]{2, 6}),
            new InputOutput(new int[]{3, 3}, 6, new int[]{0, 1}),
            new InputOutput(new int[]{1, 3, 3}, 6, new int[]{1, 2}),
            new InputOutput(new int[]{1, 3, 2, 7, 3}, 6, new int[]{1, 4})
    );

    private final Solution solution = new Solution();

    @Test
    void twoSum() {
        for (InputOutput inputOutput : inputOutputList) {
            Assertions.assertArrayEquals(inputOutput.result, solution.twoSum(inputOutput.getSource(), inputOutput.getTarget()));
        }
    }

    @Test
    void twoSumHash() {
        for (int i = 0; i < inputOutputList.size(); i++) {
            InputOutput inputOutput = inputOutputList.get(i);
            Assertions.assertArrayEquals(inputOutput.result, solution.twoSumHash(inputOutput.getSource(), inputOutput.getTarget()));
        }
    }

    @Test
    void twoSumOnceHash() {
        for (int i = 0; i < inputOutputList.size(); i++) {
            InputOutput inputOutput = inputOutputList.get(i);
            log.info("第 {} 条测试数据，input: {}, target: {}, output: {}", i + 1, inputOutput.source, inputOutput.target, inputOutput.result);
            Assertions.assertArrayEquals(inputOutput.result, solution.twoSumOnceHash(inputOutput.getSource(), inputOutput.getTarget()));
        }
    }

}